
package cookie.delete;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.e885.log.E885Logger;

/**
 * url:http://127.0.0.1:8080/JSP/cookie/deleteAdd<br>
 * <br>
 * 模擬增加一個 Cookie, 名稱為 DeleteCookie
 * 
 * @author Grady.Kao
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2000-2008
 */

public class CookieDeleteAdder extends HttpServlet
{
	private static final long serialVersionUID = 4446606258992996611L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
	{
		E885Logger.testLog.debug( "execute CookieDeleteAdder.service() to add cookie." );
		
		String value = URLEncoder.encode( "grady.kao(高清萬)", "UTF-8" );

		Cookie cookie = new Cookie( "DeleteCookie", value );
		cookie.setDomain( "127.0.0.1" );
		cookie.setPath( "/JSP" );	
		cookie.setMaxAge( 7 * 24 * 60 * 60 );	
		cookie.setVersion( 0 );		
		cookie.setSecure( false );	
		
		response.addCookie( cookie );
		
		response.setContentType( "text/html; charset=UTF-8" );
		PrintWriter writer = response.getWriter();
		writer.println( "Add Cookie 已經完成" );
		writer.close();		
	}
}
